from pyecharts import options as opts
from pyecharts.charts import Bar, Timeline

# 假设的数据
months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun']
regions = ['华北', '华东', '华南']
data = {
    'Jan': {'华北': 120, '华东': 150, '华南': 180},
    'Feb': {'华北': 110, '华东': 140, '华南': 170},
    'Mar': {'华北': 130, '华东': 160, '华南': 190},
    'Apr': {'华北': 140, '华东': 170, '华南': 200},
    'May': {'华北': 150, '华东': 180, '华南': 210},
    'Jun': {'华北': 160, '华东': 190, '华南': 220}
}

# 创建时间轴对象
timeline = Timeline()

# 遍历每个月份，创建柱状图并添加到时间轴
for month in months:
    bar = (
        Bar()
        .add_xaxis(regions)
        .add_yaxis('访问量', [data[month][region] for region in regions])
        .set_global_opts(
            title_opts=opts.TitleOpts(title=f'用户访问量 - {month}'),
            legend_opts=opts.LegendOpts(is_show=False),
            xaxis_opts=opts.AxisOpts(name='经济大区'),
            yaxis_opts=opts.AxisOpts(name='访问量')
        )
    )
    timeline.add(bar, time_point=month)

# 设置时间轴的播放选项，并渲染为HTML文件
timeline.add_schema(is_auto_play=True, play_interval=2000)
timeline.render('访问量时间轴.html')
